home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / zuck / findorcl.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  3.3 KB  |  115 lines

  1. VERSION 2.00
  2. Begin Form FindOrClose 
  3.    Caption         =   "Form2"
  4.    ClientHeight    =   2520
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   6045
  8.    Height          =   2925
  9.    Left            =   1035
  10.    LinkTopic       =   "Form2"
  11.    ScaleHeight     =   2520
  12.    ScaleWidth      =   6045
  13.    Top             =   1140
  14.    Width           =   6165
  15.    Begin CommandButton cmd_CloseIt 
  16.       Caption         =   "Close It"
  17.       Height          =   435
  18.       Left            =   2400
  19.       TabIndex        =   6
  20.       Top             =   1920
  21.       Width           =   1095
  22.    End
  23.    Begin CommandButton Command1 
  24.       Caption         =   "Ok"
  25.       Height          =   435
  26.       Left            =   4680
  27.       TabIndex        =   5
  28.       Top             =   1920
  29.       Width           =   1155
  30.    End
  31.    Begin TextBox Txt_Windows 
  32.       Height          =   315
  33.       Index           =   1
  34.       Left            =   2340
  35.       TabIndex        =   3
  36.       Top             =   480
  37.       Width           =   3075
  38.    End
  39.    Begin TextBox Txt_Windows 
  40.       Height          =   315
  41.       Index           =   0
  42.       Left            =   2340
  43.       TabIndex        =   1
  44.       Top             =   120
  45.       Width           =   3075
  46.    End
  47.    Begin Label lab_handlenum 
  48.       Caption         =   "Window Handle is:"
  49.       Height          =   195
  50.       Left            =   1560
  51.       TabIndex        =   4
  52.       Top             =   960
  53.       Width           =   3375
  54.    End
  55.    Begin Label Label2 
  56.       Alignment       =   1  'Right Justify
  57.       Caption         =   "Window Class:"
  58.       Height          =   195
  59.       Left            =   240
  60.       TabIndex        =   2
  61.       Top             =   540
  62.       Width           =   2055
  63.    End
  64.    Begin Label Label1 
  65.       Alignment       =   1  'Right Justify
  66.       Caption         =   "Window Caption:"
  67.       Height          =   195
  68.       Left            =   240
  69.       TabIndex        =   0
  70.       Top             =   180
  71.       Width           =   2055
  72.    End
  73. Option Explicit
  74. Dim CurrentHnd%
  75. Sub cmd_CloseIt_Click ()
  76.     Dim dl&
  77.     Dim hnd%
  78.     hnd% = CurrentHnd%
  79.     If hnd% <> 0 Then dl& = PostMessageBynum(hnd%, WM_CLOSE, 0, 0&)
  80. End Sub
  81. Sub Command1_Click ()
  82.     Unload Me
  83. End Sub
  84. Function FindTheWindow% ()
  85.     Dim hnd%
  86.     If txt_Windows(0).Text <> "" And txt_Windows(1).Text <> "" Then
  87.         FindTheWindow% = FindWindowByString(txt_Windows(1).Text, txt_Windows(0).Text)
  88.         Exit Function
  89.     End If
  90.     If txt_Windows(0).Text <> "" Then
  91.         FindTheWindow% = FindWindowByCaption(0&, txt_Windows(0).Text)
  92.         Exit Function
  93.     End If
  94.     If txt_Windows(1).Text <> "" Then
  95.         FindTheWindow% = FindWindowByClass(txt_Windows(1).Text, 0&)
  96.         Exit Function
  97.     End If
  98.     FindTheWindow% = 0
  99. End Function
  100. Sub Form_Load ()
  101.     Select Case LastCommand%
  102.         Case 2
  103.             Me.Caption = "Find the Window of Another App"
  104.             cmd_Closeit.Visible = 0
  105.         Case 3
  106.             Me.Caption = "Close Another App"
  107.     End Select
  108. End Sub
  109. Sub Txt_Windows_Change (Index As Integer)
  110.     Dim hnd%
  111.     hnd% = FindTheWindow()
  112.     CurrentHnd% = hnd%
  113.     lab_handlenum = "Window Handle is: " & Hex$(hnd%)
  114. End Sub
  115.